#pragma once

#include <vector>

namespace jianzhi_026
{

struct TreeNode
{
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};

class Solution
{
public:
    bool isSubStructure(TreeNode* A, TreeNode* B)
    {
        if (B == nullptr || A == nullptr)
            return false;
        return dfs(A, B) || isSubStructure(A->left, B) || isSubStructure(A->right, B);
    }

private:
    bool dfs(TreeNode* a, TreeNode* b)
    {
        if (b == nullptr)
            return true;
        if (a == nullptr || a->val != b->val)
            return false;
        return dfs(a->left, b->left) && dfs(a->right, b->right);
    }
};

}  /* namespace jianzhi_026 */
